<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







  

<link href="https://cdn.bootcss.com/font-awesome/4.6.2/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="VB," />










<meta name="description" content="前言本来我想可能不会接触到这个语言,  不过在用excel时需要用到VBA.   这就不得不专门去学习一番.   入了个门,  专门写个文档留着.  万一以后用得到呢…     论VB, 我还是初学者.  如有弄错了的地方.  你倒是来打我呀~">
<meta name="keywords" content="VB">
<meta property="og:type" content="article">
<meta property="og:title" content="VB快速上手文档教程">
<meta property="og:url" content="http://edk24.com/2017/72b8fe13.html">
<meta property="og:site_name" content="余小波の技术博客">
<meta property="og:description" content="前言本来我想可能不会接触到这个语言,  不过在用excel时需要用到VBA.   这就不得不专门去学习一番.   入了个门,  专门写个文档留着.  万一以后用得到呢…     论VB, 我还是初学者.  如有弄错了的地方.  你倒是来打我呀~">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-09-10T01:21:38.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="VB快速上手文档教程">
<meta name="twitter:description" content="前言本来我想可能不会接触到这个语言,  不过在用excel时需要用到VBA.   这就不得不专门去学习一番.   入了个门,  专门写个文档留着.  万一以后用得到呢…     论VB, 我还是初学者.  如有弄错了的地方.  你倒是来打我呀~">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://edk24.com/2017/72b8fe13.html"/>





  <title>VB快速上手文档教程 | 余小波の技术博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">余小波の技术博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">写代码的 会修电脑!</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://edk24.com/2017/72b8fe13.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="余小波">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="余小波の技术博客">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">VB快速上手文档教程</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-30T16:25:16+08:00">
                2017-12-30
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Visual-Basic/" itemprop="url" rel="index">
                    <span itemprop="name">Visual Basic</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/72b8fe13.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count gitment-comments-count" data-xid="/2017/72b8fe13.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>本来我想可能不会接触到这个语言,  不过在用excel时需要用到VBA.   这就不得不专门去学习一番.  </p>
<p>入了个门,  专门写个文档留着.  万一以后用得到呢…    </p>
<p>论VB, 我还是初学者.  如有弄错了的地方.  你倒是来打我呀~<br><a id="more"></a><br><strong><em>学习和阅读这篇文章, 需要你有其他编程经验. 我不会长篇大论的和你解释什么是”变量”什么是”循环”</em></strong></p>
<h1 id="VB-VBA-VBS-的区别"><a href="#VB-VBA-VBS-的区别" class="headerlink" title="VB/VBA/VBS 的区别"></a>VB/VBA/VBS 的区别</h1><p>VB是一门编程语言, 开发软件的.  容易上手, 但不适合开发复杂的软件.   现在快安享晚年了吧~</p>
<p>VBS使用的是VB的语法结构, 全称”VBScript”是一个脚本语言,  嵌入到网页中使用的(也有其他领域)</p>
<p>VBA的全称是”VBApplication”,  是嵌入在一些特殊软件中的.  比如Excel.  方便大家发挥骚操作</p>
<h1 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h1><table>
<thead>
<tr>
<th>类型</th>
<th>中文名称</th>
<th>大小</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>Boolean</td>
<td>布尔型</td>
<td>2字节</td>
<td>true和false</td>
</tr>
<tr>
<td>Byte</td>
<td>字节型</td>
<td>1字节</td>
<td>0~255</td>
</tr>
<tr>
<td>Integer</td>
<td>整数型</td>
<td>2字节</td>
<td>-32768～32767</td>
</tr>
<tr>
<td>Long</td>
<td>长整数</td>
<td>4字节</td>
<td>-2147483648～2147483647</td>
</tr>
<tr>
<td>Single</td>
<td>单精度浮点</td>
<td>4字节</td>
<td>-3.402823E38～-1.401298E-45(负数) <br> 1.401298E-45～3.402823E38(正数)</td>
</tr>
<tr>
<td>Double</td>
<td>双精度浮点</td>
<td>8字节</td>
<td>-1.79769313486231E308～-4.94065645841247E-324(负数) <br> 4.94065645841247E-324～1.79769313486232E308(正数)</td>
</tr>
<tr>
<td>Currency</td>
<td>货币型</td>
<td>8字节</td>
<td>-922337203685477.5808～922337203685477.5807</td>
</tr>
<tr>
<td>Decimal</td>
<td>小数型</td>
<td>14字节</td>
<td>±79228162514264337593543950335(没有小数点时)<br>±7.9228162514264337593543950335(小数点右边带28位)<br>最小的非零值为±0.0000000000000000000000000001</td>
</tr>
<tr>
<td>Date</td>
<td>日期类型</td>
<td>8字节</td>
<td>100年1月1日～9999年12月31日</td>
</tr>
<tr>
<td>Object</td>
<td>对象类型</td>
<td>4字节</td>
<td>任何对象的引用</td>
</tr>
<tr>
<td>String</td>
<td>字符串(变长)</td>
<td>10字节+字符串长度</td>
<td>0～约2亿个字符</td>
</tr>
<tr>
<td>String</td>
<td>字符串(定长)</td>
<td>字符串长度</td>
<td>1～约65400个字符</td>
</tr>
<tr>
<td>Variant(数字)</td>
<td></td>
<td>16字节</td>
<td>任何数字值，最大可达Double的范围</td>
</tr>
<tr>
<td>Variant(字符)</td>
<td></td>
<td>22字节+字符串长度</td>
<td>与可变长字符串有相同的范围</td>
</tr>
<tr>
<td>用户定义型</td>
<td></td>
<td>元素必需的数字</td>
<td>每个元素的范围与字本身数据类型的范围相同</td>
</tr>
</tbody>
</table>
<h1 id="语言风格介绍"><a href="#语言风格介绍" class="headerlink" title="语言风格介绍"></a>语言风格介绍</h1><p>快速的了解一下这个语言的风格<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Sub 功能模块()</span><br><span class="line">	If 1=1 Then</span><br><span class="line">		MsgBox &quot;对的&quot;</span><br><span class="line">	Else</span><br><span class="line">		MsgBox &quot;错的&quot;</span><br><span class="line">	End If	</span><br><span class="line">End Sub</span><br></pre></td></tr></table></figure></p>
<p>不是类C语言的风格,  一切都是语句在控制.    没有方括号,  没有”;”结尾, 没有语法糖 只能依靠缩进和换行来看懂.  </p>
<h1 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&apos;我是单行注释, 注意前面是一个单引号</span><br></pre></td></tr></table></figure>
<h1 id="常量"><a href="#常量" class="headerlink" title="常量"></a>常量</h1><p>［Public | private］Const  常量名［As 数据类型］＝表达式<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Const 文本 As String = &quot;得罪了方丈还想走?!&quot;</span><br></pre></td></tr></table></figure></p>
<p><strong><em>常量设定后, 不允许修改值</em></strong></p>
<h1 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h1><p>声明变量的方法是”Dim 变量名称 As 数据类型”<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Dim Names As String</span><br><span class="line"></span><br><span class="line">Dim Age1,Age2 As Integer = 45  &apos;声明多个变量并且赋值</span><br></pre></td></tr></table></figure></p>
<h1 id="SUB模块"><a href="#SUB模块" class="headerlink" title="SUB模块"></a>SUB模块</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[Private | Public] Sub 模块名称()</span><br><span class="line">	...</span><br><span class="line">	[Exit Sub] //退出模块</span><br><span class="line">End Sub</span><br></pre></td></tr></table></figure>
<h1 id="调用模块"><a href="#调用模块" class="headerlink" title="调用模块"></a>调用模块</h1><p>假如我们有一个”关闭”模块, 调用它就需要用到”Call”语句<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Sub 关闭()</span><br><span class="line">	...</span><br><span class="line">End Sub</span><br><span class="line"></span><br><span class="line">Call 关闭()</span><br></pre></td></tr></table></figure></p>
<h1 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h1><p>不可以忽略哦, VB的许多运算符和其他编程语言不太一样<br>|运算符|作用|举例|其他说明|<br>|—-|—-|——–|——–|<br>|=|等于|If 1 = 1 Then …||<br>|&lt;&gt;|不等于| 1 &lt;&gt; 2 ||<br>|&gt;|大于| 2 &gt; 1||<br>|>= |大于等于| | |<br>|&lt; |小于| | |<br>|&lt;=|小于等于|||<br>|+|相加|i=n+100||<br>|-|相减|i=n-50||<br>|<em>|相乘|i=500 </em> 60||<br>|/ |除法|i=36 / 3||<br>|&amp;|字符串连接|str = “你好” &amp; “我是剑齿虎”|“&amp;”是强制性连接，就是不管什么都连接。<br> VBA里用到的…    不知道通用不|<br>|+|字符串连接|str=”CHI” + “NA”|“+”是对字符串进行连接，对数字则进行加法运算。<br>（用“+”号的时候，“+”前后类型要一致）|<br>|Or| 或者 | If 1=1 Or 1=2 Then …||<br>|And| 并且| If 1=1 And 2=2 Then …||<br><br></p>
<p><strong>欢迎补充</strong></p>
<h1 id="IF判断"><a href="#IF判断" class="headerlink" title="IF判断"></a>IF判断</h1><p>简写的If<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">If 条件 Then ... [End If]</span><br></pre></td></tr></table></figure></p>
<p>支持Else和ElseIf<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">If &lt;条件1&gt; Then</span><br><span class="line">	...</span><br><span class="line">ElseIf &lt;条件2&gt;</span><br><span class="line">	...</span><br><span class="line">Else</span><br><span class="line">	...</span><br><span class="line">End If</span><br></pre></td></tr></table></figure></p>
<h1 id="Select多项选择-就是switch"><a href="#Select多项选择-就是switch" class="headerlink" title="Select多项选择 (就是switch)"></a>Select多项选择 (就是switch)</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Select Case &lt;值&gt;</span><br><span class="line">    Case 1</span><br><span class="line">        ...</span><br><span class="line">    Case 2</span><br><span class="line">        ...</span><br><span class="line">End Select</span><br></pre></td></tr></table></figure>
<h1 id="循环"><a href="#循环" class="headerlink" title="循环"></a>循环</h1><h2 id="For循环"><a href="#For循环" class="headerlink" title="For循环"></a>For循环</h2><p>来一个栗子吧,  初始化i为1.  循环100次<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">For i = 1 To 100</span><br><span class="line">	...</span><br><span class="line">	[Exit For]</span><br><span class="line">Next</span><br></pre></td></tr></table></figure></p>
<h2 id="遍历集合-遍历数组-For-Each"><a href="#遍历集合-遍历数组-For-Each" class="headerlink" title="遍历集合/遍历数组 (For Each)"></a>遍历集合/遍历数组 (For Each)</h2><p>请注意, foreach不能使用 End ForEach哦~<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">For Each cell In 集合</span><br><span class="line">	MsgBox cell.name</span><br><span class="line">Next cell</span><br></pre></td></tr></table></figure></p>
<h2 id="判断循环"><a href="#判断循环" class="headerlink" title="判断循环"></a>判断循环</h2><p>语法格式 : do While … Loop<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">do while &lt;条件&gt;</span><br><span class="line">	...</span><br><span class="line">Loop</span><br></pre></td></tr></table></figure></p>
<h2 id="循环判断"><a href="#循环判断" class="headerlink" title="循环判断"></a>循环判断</h2><p>语法格式 : do … Loop Until &lt;条件&gt;<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Do</span><br><span class="line">	...</span><br><span class="line">Loop Until &lt;条件&gt;</span><br></pre></td></tr></table></figure></p>
<h1 id="恭喜您-你已经入门了VB-并解锁了以下技能"><a href="#恭喜您-你已经入门了VB-并解锁了以下技能" class="headerlink" title="恭喜您, 你已经入门了VB. 并解锁了以下技能"></a>恭喜您, 你已经入门了VB. 并解锁了以下技能</h1><ul>
<li>语法结构</li>
<li>注释</li>
<li>常量</li>
<li>变量</li>
<li>模块/函数</li>
<li>判断语句</li>
<li>循环语句</li>
</ul>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/VB/" rel="tag"># VB</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/e4307f35.html" rel="next" title="C# API复制/拷贝到剪辑板">
                <i class="fa fa-chevron-left"></i> C# API复制/拷贝到剪辑板
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/accf8bae.html" rel="prev" title="Electron创建项目并打包生成exe">
                Electron创建项目并打包生成exe <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      
        <div id="gitment-container"></div>
      
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.png"
                alt="余小波" />
            
              <p class="site-author-name" itemprop="name">余小波</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">34</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">27</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">57</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/edk24" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:yuxiaobo64@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://space.bilibili.com/10396559" target="_blank" title="Bilibili">
                      
                        <i class="fa fa-fw fa-play"></i>Bilibili</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://twitter.com/SabreCode" target="_blank" title="Twitter">
                      
                        <i class="fa fa-fw fa-twitter"></i>Twitter</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#VB-VBA-VBS-的区别"><span class="nav-number">2.</span> <span class="nav-text">VB/VBA/VBS 的区别</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#数据类型"><span class="nav-number">3.</span> <span class="nav-text">数据类型</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#语言风格介绍"><span class="nav-number">4.</span> <span class="nav-text">语言风格介绍</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#注释"><span class="nav-number">5.</span> <span class="nav-text">注释</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#常量"><span class="nav-number">6.</span> <span class="nav-text">常量</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#变量"><span class="nav-number">7.</span> <span class="nav-text">变量</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SUB模块"><span class="nav-number">8.</span> <span class="nav-text">SUB模块</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#调用模块"><span class="nav-number">9.</span> <span class="nav-text">调用模块</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#运算符"><span class="nav-number">10.</span> <span class="nav-text">运算符</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#IF判断"><span class="nav-number">11.</span> <span class="nav-text">IF判断</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Select多项选择-就是switch"><span class="nav-number">12.</span> <span class="nav-text">Select多项选择 (就是switch)</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#循环"><span class="nav-number">13.</span> <span class="nav-text">循环</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#For循环"><span class="nav-number">13.1.</span> <span class="nav-text">For循环</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#遍历集合-遍历数组-For-Each"><span class="nav-number">13.2.</span> <span class="nav-text">遍历集合/遍历数组 (For Each)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#判断循环"><span class="nav-number">13.3.</span> <span class="nav-text">判断循环</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#循环判断"><span class="nav-number">13.4.</span> <span class="nav-text">循环判断</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#恭喜您-你已经入门了VB-并解锁了以下技能"><span class="nav-number">14.</span> <span class="nav-text">恭喜您, 你已经入门了VB. 并解锁了以下技能</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">余小波</span>

  
</div>









        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.1.3/jquery.min.js"></script>
  

  
  
    <script type="text/javascript" src="https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
  

  
  
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery_lazyload/1.9.7/jquery.lazyload.min.js"></script>
  

  
  
    <script type="text/javascript" src="https://cdn.bootcss.com/velocity/1.2.1/velocity.min.js"></script>
  

  
  
    <script type="text/javascript" src="https://cdn.bootcss.com/velocity/1.2.1/velocity.ui.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  







<!-- LOCAL: You can save these files to your site and update links -->
    
        
        <link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css">
        <script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script>
    
<!-- END LOCAL -->

    
      <style>
        a.gitment-editor-footer-tip { display: none; }
        .gitment-container.gitment-footer-container { display: none; }
      </style>
    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitmint({
            id: window.location.pathname, 
            owner: 'edk24',
            repo: 'edk24.github.io',
            
            lang: "" || navigator.language || navigator.systemLanguage || navigator.userLanguage,
            
            oauth: {
            
            
                client_secret: 'fe67c38e961d9727108fbea7ad37a022c375449e',
            
                client_id: 'd555d8a2acc95a3ff25e'
            }});
        gitment.render('gitment-container');
      }

      
      renderGitment();
      
      </script>
    







  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
